/*******************************************************************************
 * Copyright (c) 2001, 2002 Boris Pruessmann and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 *    Boris Pruessmann - Initial implementation.
 ******************************************************************************/
package net.sourceforge.perforce.ui.dialogs;

import net.sourceforge.perforce.core.resources.IChangelist;
import net.sourceforge.perforce.core.resources.IP4File;
import net.sourceforge.perforce.ui.internal.Policy;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;

/**
  * @version 	$Revision: 196 $
  * @author		<a href="mailto:bpruessmann@users.sourceforge.net">Boris Pruessmann</a>
  */
public class DescribeChangelistDialog extends AbstractChangeSpecDialog 
{
	// --------------------------------------------------------------------------- Private Variables
	
	/** Stores the changelist to describe. */
	private IChangelist changelist;
	
	// ------------------------------------------------------------------------- Public Constructors
	
	/** Constructor for DescribeChangelistDialog.
	  *
	  * @param shell the parent shell.
	  * @param aChangelist the changelist to describe.
	  * 
	  * @see AbstractChangeSpecDialog#AbstractChangeSpecDialog(Shell)
	  */
	public DescribeChangelistDialog(Shell shell, IChangelist aChangelist)
	{
		super(shell);
		changelist = aChangelist;
	}
	
	// --------------------------------------------------------------------------- Protected Methods
	
	/** @see AbstractChangeSpecDialog#createDescriptionTextControl(Composite, int) */
	protected Text createDescriptionTextControl(Composite composite, int style) 
	{
		return super.createDescriptionTextControl(composite, style | SWT.READ_ONLY);
	}
	
	/** @see AbstractChangeSpecDialog#createFileTableControl(Composite, int) */
	protected Table createFileTableControl(Composite parent, int style) 
	{
		return super.createFileTableControl(parent, style & ~SWT.CHECK);
	}
	
	// ------------------------------------------------------------------------------------- Methods
		
	/** @see AbstractChangeSpecDialog#getChangelist() */
	String getChangelist() 
	{
		int id = changelist.getId().intValue();
		return (id == IChangelist.DEFAULT.intValue()) ? "Default" : changelist.getId().toString(); 
	}

	/** @see AbstractChangeSpecDialog#getClientName() */
	String getClientName() 
	{
		return changelist.getClientName();
	}

	/** @see AbstractChangeSpecDialog#getDate() */
	String getDate() 
	{
		// TODO:
		return changelist.getDate().toString();
	}

	/** @see AbstractChangeSpecDialog#getDescription() */
	String getDescription() 
	{
		return changelist.getDescription();
	}

	/** @see AbstractChangeSpecDialog#getFiles() */
	String[] getFiles() 
	{
		IP4File[] files = changelist.getFiles();
		String[] result = new String[files.length];
		for (int i = 0; i < result.length; i++)
		{
			result[i] = files[i].getDepotFilename();
		} 
		return result;
	}

	/** @see AbstractChangeSpecDialog#getStatus() */
	String getStatus() 
	{
		return changelist.getStatus();
	}

	/** @see AbstractChangeSpecDialog#getTitle() */
	String getTitle() 
	{
		return Policy.bind("ChangeSpecDialog.dialogTitleReadOnly");                     //NON-NLS-1$
	}

	/** @see AbstractChangeSpecDialog#getUserName() */
	String getUserName() 
	{
		return changelist.getUserName();
	}
}
